<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-form
          label-width="100px"
          v-formkey="{ query: toQuery }"
          size="small"
        >
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="关键字">
                <el-input
                  v-model="query.keyword"
                  placeholder="输入关键字搜索"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品类型">
                <zSelect
                  :value.sync="query.goodsTagId"
                  url="api/dropDown/basGoodsTagList"
                  style="width: 100%"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品分类">
                <treeselect
                  v-model="query.goodsTypeId"
                  :options="typeList"
                  placeholder="选择商品分类"
                  style="width: 100%"
                  :normalizer="normalizer"
                >
                </treeselect>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品品牌">
                <zSelect
                  :value.sync="query.goodsBrandId"
                  url="api/dropDown/basGoodsBrandList"
                  style="width: 100%"
                >
                </zSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="税率">
                <el-input
                  v-model="query.taxRate"
                  type="Number"
                  placeholder="输入税率搜索"
                  style="width: 100%"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="状态">
                <el-select
                  v-model="query.status"
                  class="edit-input"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in dict.common_status"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="6" :md="8" :sm="12" :xl="6" :xs="24">
              <el-form-item label="是否保质期管理">
                <el-select
                  v-model="query.isExpirationManage"
                  class="edit-input"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in dict.common_yes_or_no"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="6" :md="8" :sm="12" :xl="6" :xs="24">
              <el-form-item label="是否批次管理">
                <el-select
                  v-model="query.isBatchManage"
                  class="edit-input"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option
                    v-for="(item, index) in dict.common_yes_or_no"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商">
                <zSelect
                  :value.sync="query.supplierId"
                  url="api/dropDown/basCustomerList"
                  :params="{ isContact: '1,2' }"
                  style="width: 100%"
                >
                </zSelect>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否有图片">
                <el-select v-model="query.hasImage">
                  <el-option label="是" value="1"> </el-option>
                  <el-option label="否" value="0"> </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <rrOperation :crud="crud" />
      </div>

      <crudOperation :permission="permission">
        <el-button
          slot="left"
          v-permission="['admin', 'basGoods:edit']"
          class="filter-item"
          size="mini"
          type="primary"
          @click="toAdd"
        >
          新增
        </el-button>
        <el-button
          slot="left"
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="success"
          @click="crud.enableOrDisable('ENABLE')"
          >启用</el-button
        >
        <el-button
          slot="left"
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="danger"
          @click="crud.enableOrDisable('DISABLE')"
          >禁用</el-button
        >
        <el-button
          slot="left"
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="danger"
          :disabled="crud.selections.length<1"
          @click="relevance"
          >客户商品关联设置</el-button
        >
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          type="primary"
          :disabled="crud.selections.length < 1"
          @click="pushBasGoodsToMd"
        >
          推送商品
        </el-button>
      </crudOperation>
    </div>

    <div class="body-container">
      <vue-context-menu
        :contextMenuData="contextMenuData"
        @tableConfig="tableConfig"
        @deletedata="deletedata"
      ></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置" :visible.sync="tableConfigShow" width="60%">
        <j-table-column-config
          :columns.sync="crud.header"
          @tabSave="tabSave"
          @pit="pit"
        />
      </el-dialog>
      <!-- 关联弹框 -->
      <el-dialog title="客户商品关联" :visible.sync="dialogVisible" width="70%">
        <el-form label-width="70px" size="small">
          <el-row >
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="客户名称">
                <!-- <zSelect
                  :value.sync="form.customerId"
                  url="api/dropDown/basCustomerList"
                  multiple
                /> -->
                <table-select
                  :tableColumns="
                  [
                  {prop:'code',label:'客户编码',width: '100'},
                  {prop:'name',label:'客户名称',width: '150'},
                  {prop:'sCustomerName',label:'二批'},
                  ]"
                  labelKey="name"
                  valueKey="id"
                  width="300"
                  :value.sync="form.customerId"
                  placeholder="请选择客户"
                  url="api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="客户区域">
                <treeselect
                  v-model="form.customerAreaIds"
                  :options="areaList"
                  placeholder="客户区域"
                  :normalizer="normalizer"
                  multiple
                  @input="(val) => getNoStr(val, 'areaList', 'customerAreaIds')"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="客户分类">
                <treeselect
                  v-model="form.customerTypeIds"
                  :options="CustomerType"
                  placeholder="客户分类"
                  :normalizer="normalizer"
                  multiple
                  @input="(val) => getNoStr(val, 'CustomerType', 'customerTypeIds')"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="所属商贸">
                <table-select
                  multiple
                  :tableColumns="[
                    { prop: 'code', label: '编码', width: '100' },
                    { prop: 'name', label: '名称', width: '280' },
                  ]"
                  :value.sync="form.fCustomerId"
                  placeholder="请选择商贸公司"
                  url="/api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="所属二批">
                <table-select
                  multiple
                  :tableColumns="[
                    { prop: 'code', label: '二批编码', width: '100' },
                    { prop: 'name', label: '二批名称', width: '280' },
                  ]"
                  :value.sync="form.sCustomerId"
                  placeholder="请选择所属二批"
                  url="/api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-button
              class="filter-item"
              size="mini"
              type="primary"
              @click="tuery"
              >查询</el-button
            >
            <el-button
              class="filter-item"
              plain
              size="mini"
              type="primary"
              @click="resetQuery"
              >重置</el-button
            >
          </el-row>
          <el-row>
            <el-button style="margin-bottom: 10px;" class="filter-item" size="mini" type="primary" :loading="crud.rejectLoading" @click="save"> 保存 </el-button>
            <el-button style="margin-bottom: 10px;" class="filter-item" size="mini" type="primary" :loading="crud.rejectLoading" @click="yes"> 批量设置是 </el-button>
            <el-button style="margin-bottom: 10px;" class="filter-item" size="mini" type="primary" :loading="crud.rejectLoading" @click="no"> 批量设置否 </el-button>
          </el-row>
        <el-table ref="table1" border v-loading="crud.loading" :data="tabledata" size="small"  @row-click="selectRow"  >
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column prop="customerCode" label="客户编码"/>
        <el-table-column prop="customerName" label="客户名称"/>
        <el-table-column prop="customerTypeName" label="客户分类"/>
        <el-table-column  prop="customerAreaName" label="客户区域"/>
        <el-table-column  prop="fCustomerName" label="所属商贸"/>
        <el-table-column  prop="sCustomerName" label="所属二批"/>
        <el-table-column  prop="isAllowSale" label="是否允许销售">
          <template slot-scope="scope">
          {{ dict.label.common_yes_or_no[scope.row.isAllowSale] }}
        </template>
        </el-table-column>
        <el-table-column  label="操作" width="150" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click.stop="permit(scope.row)">是</el-button>
            <el-button size="mini" type="primary" @click.stop="notallow(scope.row)">否</el-button>
          </template>
        </el-table-column>
          </el-table>
          <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[10, 20, 30, 40, 50, 100, 200,1000]"
      :page-size="size"
      layout="total,  prev, pager, next,sizes"
      :total="total">
    </el-pagination>
      </el-form ><!-- </span> -->
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        border
        :height="tableHeight"
        show-summary
        @cell-dblclick="(row) => crud.toEdit(row)"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%"
        @sort-change="sortTab"
        v-if="isShowTable"
        @header-dragend="changeColWidth"
        @contextmenu.native="showMenu"
        :summary-method="crud.sumRow"
        @row-click="crud.selectRow"
        :row-style="crud.rowClass"
        :row-class-name="crud.tableRowClassName"
        @row-dblclick="toDetail"
        @selection-change="crud.selectionChangeHandler">
        <el-table-column
          :render-header="crud.renderHeader"
          type="selection"
          width="60"
        />
        <el-table-column
          :render-header="crud.renderHeader"
          type="index"
          width="60"
          label="序号"
        />
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp="item.prop"
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
          :sortable="item.sortable ? 'custom' : false"
          :sort-orders="['descending', 'ascending', null]"
          sort-change="sort"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template>
              <span v-if="item.type == 1" style="margin-left: 0px">{{
                scope.row[`${item.prop}`]
              }}</span>
              <span v-else-if="item.type == 2" style="margin-left: 0px">{{
                parseTime(scope.row[`${item.prop}`])
              }}</span>
              <span v-else-if="item.type == 3" style="margin-left: 0px">{{
                getDict(
                  `this.dict.label.${item.dictionary}["${
                    scope.row[item.prop]
                  }"]`
                )
              }}</span>
              <span v-else-if="item.prop == 'image'">
                <el-image
                  v-if="scope.row.image"
                  style="width: 30px; height: 30px"
                  :src="scope.row.image"
                  :preview-src-list="[scope.row.image]"
                />
              </span>
            </template>
          </template>
        </el-table-column>
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编码"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" prop="name" label="名称"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('type')" prop="type" label="商品类型" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sourceType')" prop="sourceType" label="来源类型(1:手动添加 2:导入)" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('helpSign')" prop="helpSign" label="助记符"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('spell')" prop="spell" label="拼音"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('model')" prop="model" label="规格型号"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('barcode')" prop="barcode" label="条形码"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxBarcode')" prop="boxBarcode" label="箱装条形码"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('firstUnitId')" prop="firstUnitId" label="一级单位id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('firstUnitCode')" prop="firstUnitCode" label="一级单位编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('firstUnitName')" prop="firstUnitName" label="一级单位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('firstUnitCount')" prop="firstUnitCount" label="一级单位计量数"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('secondUnitId')" prop="secondUnitId" label="二级单位id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('secondUnitCode')" prop="secondUnitCode" label="二级单位编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('secondUnitName')" prop="secondUnitName" label="二级单位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('secondUnitCount')" prop="secondUnitCount" label="二级单位计量数"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('thirdUnitId')" prop="thirdUnitId" label="三级单位id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('thirdUnitCode')" prop="thirdUnitCode" label="三级单位编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('thirdUnitName')" prop="thirdUnitName" label="三级单位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('thirdUnitCount')" prop="thirdUnitCount" label="三级单位计量数"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('fourthUnitId')" prop="fourthUnitId" label="四级单位id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('fourthUnitCode')" prop="fourthUnitCode" label="四级单位编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('fourthUnitName')" prop="fourthUnitName" label="四级单位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('fourthUnitCount')" prop="fourthUnitCount" label="四级单位计量数"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minSaleUnitId')" prop="minSaleUnitId" label="最小销售单位id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minSaleUnitCode')" prop="minSaleUnitCode" label="最小销售单位编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minSaleUnitName')" prop="minSaleUnitName" label="最小销售单位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minSaleUnitCount')" prop="minSaleUnitCount" label="最小销售单位计量数"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minReturnUnitId')" prop="minReturnUnitId" label="最小退货单位id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minReturnUnitCode')" prop="minReturnUnitCode" label="最小退货单位编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minReturnUnitName')" prop="minReturnUnitName" label="最小退货单位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minReturnUnitCount')" prop="minReturnUnitCount" label="最小退货单位计量数"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsBrandId')" prop="goodsBrandId" label="商品品牌id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsBrandCode')" prop="goodsBrandCode" label="商品品牌编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsBrandName')" prop="goodsBrandName" label="商品品牌"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxRate')" prop="taxRate" label="税率"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTypeId')" prop="goodsTypeId" label="商品分类id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTypeCode')" prop="goodsTypeCode" label="商品分类编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTypeName')" prop="goodsTypeName" label="商品分类"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTagId')" prop="goodsTagId" label="商品类型id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTagCode')" prop="goodsTagCode" label="商品类型编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTagName')" prop="goodsTagName" label="商品类型"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsLevel')" prop="goodsLevel" label="商品品级">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.t_bas_goods_level[scope.row.goodsLevel] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerId')" prop="customerId" label="客户id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerCode')" prop="customerCode" label="客户编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerName')" prop="customerName" label="供应商"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('fCustomerId')" prop="fCustomerId" label="所属商贸公司id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('fCustomerCode')" prop="fCustomerCode" label="所属商贸公司编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('fCustomerName')" prop="fCustomerName" label="所属商贸公司"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isBatchManage')" prop="isBatchManage"-->
        <!--                         label="是否批次管理">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_yes_or_no[scope.row.isBatchManage] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isExpirationManage')" prop="isExpirationManage"-->
        <!--                         label="是否保质期管理">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_yes_or_no[scope.row.status] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isBulk')" prop="isBulk" label="是否散装">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_yes_or_no[scope.row.status] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isPromotion')" prop="isPromotion" label="是否促销">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_yes_or_no[scope.row.status] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('expiration')" prop="expiration" label="保质期"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('expirationUnit')" prop="expirationUnit" label="保质期单位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('newGoodsExpir')" prop="newGoodsExpir" label="新商品标志期限"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('newGoodsExpirDate')" prop="newGoodsExpirDate" label="新商品标志截止日期">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.newGoodsExpirDate) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('buySaleType')" prop="buySaleType" label="购销类型">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.t_bas_goods_buy_sale_type[scope.row.buySaleType] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('priceType')" prop="priceType" label="计价方式">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.t_bas_goods_price_type[scope.row.priceType] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.packageType"  prop="packageType" label="包装类型">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.t_bas_goods_package_type[scope.row.priceType] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('buyTaxPrice')" prop="buyTaxPrice" label="采购含税价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('buyNoTaxPrice')" prop="buyNoTaxPrice" label="采购未税价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('buyTaxBoxPrice')" prop="buyTaxBoxPrice" label="采购含税箱价">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.buyTaxBoxPrice }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('buyNoTaxBoxPrice')" prop="buyNoTaxBoxPrice" label="采购未税箱价">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.buyNoTaxBoxPrice }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleTaxPrice')" prop="saleTaxPrice" label="销售含税单价">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.saleTaxPrice }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleNoTaxPrice')" prop="saleNoTaxPrice" label="销售未税单价">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.saleNoTaxPrice }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleTaxBoxPrice')" prop="saleTaxBoxPrice" label="销售含税箱价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('saleNoTaxBoxPrice')" prop="saleNoTaxBoxPrice" label="销售未税箱价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestBuyTaxPrice')" prop="latestBuyTaxPrice" label="最近采购含税单价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestBuyNoTaxPrice')" prop="latestBuyNoTaxPrice" label="最近采购未税单价">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.latestBuyNoTaxPrice }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestBuyTaxBoxPrice')" prop="latestBuyTaxBoxPrice" label="最近采购含税箱价">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.latestBuyTaxBoxPrice }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestBuyNoTaxBoxPrice')" prop="latestBuyNoTaxBoxPrice" label="最近采购未税箱价">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ scope.row.latestBuyNoTaxBoxPrice }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestSaleTaxPrice')" prop="latestSaleTaxPrice" label="最近销售含税单价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestSaleNoTaxPrice')" prop="latestSaleNoTaxPrice" label="最近销售未税单价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestSaleTaxBoxPrice')" prop="latestSaleTaxBoxPrice" label="最近销售含税箱价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestSaleNoTaxBoxPrice')" prop="latestSaleNoTaxBoxPrice"-->
        <!--                         label="最近销售未税箱价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestPromotionTaxPrice')" prop="latestPromotionTaxPrice"-->
        <!--                         label="最近促销含税单价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestPromotionNoTaxPrice')" prop="latestPromotionNoTaxPrice"-->
        <!--                         label="最近促销未税单价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestPromotionTaxBoxPrice')" prop="latestPromotionTaxBoxPrice"-->
        <!--                         label="最近促销含税箱价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestPromotionNoTaxBoxPrice')" prop="latestPromotionNoTaxBoxPrice"-->
        <!--                         label="最近促销未税箱价"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestCustomerId')" prop="latestCustomerId" label="最近采购客户id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestCustomerCode')" prop="latestCustomerCode" label="最近采购客户编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('latestCustomerName')" prop="latestCustomerName" label="最近采购客户"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('length')" prop="length" label="长"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('width')" prop="width" label="宽"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('height')" prop="height" label="高"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('volume')" prop="volume" label="箱体积"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('weight')" prop="weight" label="箱重"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('imageUrl')" prop="imageUrl" label="图片地址"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('minStock')" prop="minStock" label="最低库存"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('maxStock')" prop="maxStock" label="最高库存"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('safeStock')" prop="safeStock" label="安全库存"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('warehouseId')" prop="warehouseId" label="默认仓库id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('warehouseCode')" prop="warehouseCode" label="默认仓库编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('warehouseName')" prop="warehouseName" label="默认仓库"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('storehouseId')" prop="storehouseId" label="默认库位id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('storehouseCode')" prop="storehouseCode" label="默认库位编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('storehouseName')" prop="storehouseName" label="默认库位"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('standardBoxCount')" prop="standardBoxCount" label="标箱数量"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isAppletSale')" prop="isAppletSale" label="是否小程序销售">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_yes_or_no[scope.row.isAppletSale] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('seq')" prop="seq" label="排序"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('status')" prop="status" label="状态">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.common_status[scope.row.status] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createUserId')" prop="createUserId" label="添加人id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createUserCode')" prop="createUserCode" label="添加人编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createUserName')" prop="createUserName" label="添加人"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createTime')" prop="createTime" label="添加时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.createTime) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateUserId')" prop="updateUserId" label="修改人id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateUserCode')" prop="updateUserCode" label="修改人编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateUserName')" prop="updateUserName" label="修改人"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateTime')" prop="updateTime" label="修改时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.updateTime) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxId')" prop="taxId" label="税种id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxCode')" prop="taxCode" label="税种编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxName')" prop="taxName" label="税种"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('costTaxPrice')" prop="costTaxPrice" label="含税成本价"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('costNoTaxPrice')" prop="costNoTaxPrice" label="未税成本价"/>-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('locationId')" prop="locationId" label="库区id" />&ndash;&gt;-->
        <!--        &lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('locationCode')" prop="locationCode" label="库区编码" />&ndash;&gt;-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('locationName')" prop="locationName" label="库区"/>-->
        <!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','basGoods:edit','basGoods:del']" label="操作" width="150px"-->
        <!--                         align="center" fixed="right">-->
        <!--          <template slot-scope="scope">-->
        <!--            <udOperation-->
        <!--                :data="scope.row"-->
        <!--                :permission="permission"-->
        <!--            >-->
        <!--              <el-tooltip class="item" content="复制" effect="light" placement="top"  slot="left">-->
        <!--                <i class="el-icon-copy-document opration_icon_btn" style="margin-right: 14px"  @click="toCopy(scope.row)"/>-->
        <!--              </el-tooltip>-->

        <!--            </udOperation>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudBasGoods from "@/api/erp/basGoods";
import CRUD, { crud, form, header, presenter } from "@crud/crud";
import rrOperation from "@crud/RR.operation";
import crudOperation from "@crud/CRUD.operation";
import udOperation from "@crud/UD.operation";
import pagination from "@crud/Pagination";
import Treeselect from "@riophae/vue-treeselect";
import { getTypeList } from "@/api/erp/basGoodsType";
import {getCustomerTypeTree} from "@/api/erp/basCustomerType";
import { getAreaTree } from "@/api/erp/basCustomerArea";
import { publicListKey } from "@/utils/key";
import { getHeaderProperties } from "@/api/erp/headerProperties";
import { tablemixins } from "@/mixins/tablemixins";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";

// crud交由presenter持有
const defaultCrud = CRUD({
  title: "商品档案",
  url: "api/basGoods",
  sort: "code,asc",
  crudMethod: { ...crudBasGoods },
  optShow: {
    add: false,
    edit: false,
    del: true,
    download: true,
    leadingIn: true,
    enable: false,
    disable: false,
  },
  query: {
    hasImage: null,
  },
  props: {
    //在这里配置要显示的字段
    showColumns: [
      // 'code',  //"编码"
      "name", //"名称"
      "type", //"商品类型(1:默认)"
      "sourceType", //"来源类型(1:手动添加 2:导入)"
      "helpSign", //"助记符"
      // 'spell',   //"拼音"
      "model", //"规格型号"
      // 'barcode',   //"条形码"
      // 'boxBarcode',   //"箱装条形码"
      // 'firstUnitCode',   //"一级单位编码"
      "firstUnitName", //"一级单位名称"
      "firstUnitCount", //"一级单位计量数"
      // 'secondUnitCode',   //"二级单位编码"
      "secondUnitName", //"二级单位名称"
      "secondUnitCount", //"二级单位计量数"
      // 'thirdUnitCode',   //"三级单位编码"
      // 'thirdUnitName',   //"三级单位名称"
      // 'thirdUnitCount',   //"三级单位计量数"
      // 'fourthUnitCode',   //"四级单位编码"
      // 'fourthUnitName',   //"四级单位名称"
      // 'fourthUnitCount',   //"四级单位计量数"
      // 'minSaleUnitCode',   //"最小销售单位编码"
      "minSaleUnitName", //"最小销售单位名称"
      "minSaleUnitCount", //"最小销售单位计量数"
      // 'minReturnUnitCode',   //"最小退货单位编码"
      "minReturnUnitName", //"最小退货单位名称"
      "minReturnUnitCount", //"最小退货单位计量数"
      // 'goodsBrandCode',   //"商品品牌编码"
      "goodsBrandName", //"商品品牌名称"
      "taxRate", //"税率"
      // 'goodsTypeCode',   //"商品分类编码"
      "goodsTypeName", //"商品分类名称"
      // 'goodsTagCode',   //"商品类型编码"
      "goodsTagName", //"商品类型名称"
      // 'goodsLevel',   //"商品品级(PERFECT:优等品 GRADE_ONE:一等品 QUALLIFIED:合格品 FAILE:不合格品)"
      // 'customerCode',   //"客户编码"
      "customerName", //"客户名称"
      // 'fCustomerCode',   //"所属商贸公司编码"
      "fCustomerName", //"所属商贸公司名称"
      "isBatchManage", //"是否批次管理(0:否 1:是)"
      "isExpirationManage", //"是否保质期管理(0:否 1:是)"
      "isBulk", //"是否散装(0:否 1:是)"
      "isPromotion", //"是否促销(0:否 1:是)"
      // 'expiration',   //"保质期"
      // 'expirationUnit',   //"保质期单位(DAY:天 WEEK:周 MONTH:月 YEAR:年)"
      "newGoodsExpir", //"新商品标志期限(单位月)"
      "newGoodsExpirDate", //"新商品标志截止日期"
      "buySaleType", //"购销类型(BUY_SALE:购销 BUY:可购 SALE:可销)"
      // 'priceType',   //"计价方式(SINGLE:单品 BOX:箱)"
      "buyTaxPrice", //"采购含税价"
      "buyNoTaxPrice", //"采购未税价"
      "buyTaxBoxPrice", //"采购含税箱价"
      "buyNoTaxBoxPrice", //"采购未税箱价"
      "saleTaxPrice", //"销售含税单价"
      "saleNoTaxPrice", //"销售未税单价"
      "saleTaxBoxPrice", //"销售含税箱价"
      "saleNoTaxBoxPrice", //"销售未税箱价"
      "latestBuyTaxPrice", //"最近采购含税单价"
      "latestBuyNoTaxPrice", //"最近采购未税单价"
      "latestBuyTaxBoxPrice", //"最近采购含税箱价"
      "latestBuyNoTaxBoxPrice", //"最近采购未税箱价"
      "latestSaleTaxPrice", //"最近销售含税单价"
      "latestSaleNoTaxPrice", //"最近销售未税单价"
      "latestSaleTaxBoxPrice", //"最近销售含税箱价"
      "latestSaleNoTaxBoxPrice", //"最近销售未税箱价"
      "latestPromotionTaxPrice", //"最近促销含税单价"
      "latestPromotionNoTaxPrice", //"最近促销未税单价"
      "latestPromotionTaxBoxPrice", //"最近促销含税箱价"
      "latestPromotionNoTaxBoxPrice", //"最近促销未税箱价"
      // 'latestCustomerCode',   //"最近采购客户编码"
      "latestCustomerName", //"最近采购客户名称"
      // 'length',   //"长"
      // 'height',   //"高"
      // 'volume',   //"箱体积"
      // 'weight',   //"箱重"
      "imageUrl", //"图片地址"
      "minStock", //"最低库存"
      "maxStock", //"最高库存"
      "safeStock", //"安全库存"
      // 'warehouseCode',   //"默认仓库编码"
      "warehouseName", //"默认仓库名称"
      // 'storehouseCode',   //"默认库位编码"
      "storehouseName", //"默认库位名称"
      "standardBoxCount", //"标箱数量"
      "isAppletSale", //"是否小程序销售(0:否 1:是)"
      "seq", //"排序"
      "status", //"状态(0:禁用 1:启用)"
      "remark", //"备注"
      // 'createUserCode',   //"添加人编码"
      // 'createUserName',   //"添加人名称"
      // 'createTime',   //"添加时间"
      // 'updateUserCode',   //"修改人编码"
      // 'updateUserName',   //"修改人名称"
      // 'updateTime',   //"修改时间"
      // 'taxCode',   //"税种编码"
      "taxName", //"税种名称"
      "costTaxPrice", //"含税成本价"
      "costNoTaxPrice", //"未税成本价"
      // 'locationCode',   //"库区编码"
      "locationName", //"库区名称"
    ],
  },
});
const defaultForm = {
  id: null,
  code: null,
  name: null,
  type: null,
  sourceType: null,
  helpSign: null,
  spell: null,
  model: null,
  barcode: null,
  boxBarcode: null,
  firstUnitId: null,
  firstUnitCode: null,
  firstUnitName: null,
  firstUnitCount: null,
  secondUnitId: null,
  secondUnitCode: null,
  secondUnitName: null,
  secondUnitCount: null,
  thirdUnitId: null,
  thirdUnitCode: null,
  thirdUnitName: null,
  thirdUnitCount: null,
  fourthUnitId: null,
  fourthUnitCode: null,
  fourthUnitName: null,
  fourthUnitCount: null,
  minSaleUnitId: null,
  minSaleUnitCode: null,
  minSaleUnitName: null,
  minSaleUnitCount: null,
  minReturnUnitId: null,
  minReturnUnitCode: null,
  minReturnUnitName: null,
  minReturnUnitCount: null,
  goodsBrandId: null,
  goodsBrandCode: null,
  goodsBrandName: null,
  taxRate: null,
  goodsTypeId: null,
  goodsTypeCode: null,
  goodsTypeName: null,
  goodsTagId: null,
  goodsTagCode: null,
  goodsTagName: null,
  goodsLevel: null,
  customerId: null,
  customerCode: null,
  customerName: null,
  fCustomerId: null,
  sCustomerId: null,
  fCustomerCode: null,
  fCustomerName: null,
  isBatchManage: null,
  isExpirationManage: null,
  isBulk: null,
  isPromotion: null,
  expiration: null,
  expirationUnit: null,
  newGoodsExpir: null,
  newGoodsExpirDate: null,
  buySaleType: null,
  priceType: null,
  buyTaxPrice: null,
  buyNoTaxPrice: null,
  buyTaxBoxPrice: null,
  buyNoTaxBoxPrice: null,
  saleTaxPrice: null,
  saleNoTaxPrice: null,
  saleTaxBoxPrice: null,
  saleNoTaxBoxPrice: null,
  latestBuyTaxPrice: null,
  latestBuyNoTaxPrice: null,
  latestBuyTaxBoxPrice: null,
  latestBuyNoTaxBoxPrice: null,
  latestSaleTaxPrice: null,
  latestSaleNoTaxPrice: null,
  latestSaleTaxBoxPrice: null,
  latestSaleNoTaxBoxPrice: null,
  latestPromotionTaxPrice: null,
  latestPromotionNoTaxPrice: null,
  latestPromotionTaxBoxPrice: null,
  latestPromotionNoTaxBoxPrice: null,
  latestCustomerId: null,
  latestCustomerCode: null,
  latestCustomerName: null,
  length: null,
  width: null,
  height: null,
  volume: null,
  weight: null,
  imageUrl: null,
  minStock: null,
  maxStock: null,
  safeStock: null,
  warehouseId: null,
  warehouseCode: null,
  warehouseName: null,
  storehouseId: null,
  storehouseCode: null,
  storehouseName: null,
  standardBoxCount: null,
  isAppletSale: null,
  seq: null,
  status: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null,
  customerAreaIds: [],
};
export default {
  name: "BasGoods",
  components: {
    pagination,
    crudOperation,
    rrOperation,
    udOperation,
    Treeselect,
    jTableColumnConfig,
  },
  mixins: [
    presenter(defaultCrud),
    header(),
    form(defaultForm),
    crud(),
    publicListKey,
    tablemixins,
  ],
  dicts: [
    "t_bas_goods_type",
    "common_status",
    "t_bas_goods_buy_sale_type",
    "common_yes_or_no",
    "t_bas_goods_price_type",
    "t_bas_goods_expiration_unit",
    "t_bas_goods_level",
    "t_bas_goods_source_type",
    "t_bas_goods_package_type",
    "t_bas_goods_buy_sale_type",
    "t_bas_goods_brand_type",
    "t_bas_goods_tag_type",
  ],
  data() {
    return {
      tableHeight: 0,
      permission: {
        //add 不添加权限，这个add按钮自定义
        add: ["a"],
        edit: ["a"],
        del: ["admin", "basGoods:del"],
        import: ["admin", "basGoods:import"],
        export: ["admin", "basGoods:export"],
        copy: ["admin", "basGoods:copy"],
        upload: ["admin", "basGoods:upload"],
        download: ["admin", "basGoods:download"],
        enable: ["admin", "basGoods:enable"],
        disable: ["admin", "basGoods:disable"],
      },
      rules: {},
      brandList: [],
      CustomerType: [],
      typeList: [],
      areaList: [],
      dialogVisible: false,
      selection:[],
      tabledata:[],
      customerTypeIds:[],
      total:0,
      page:1,
      size:20
    };
  },
  watch: {},
  created() {
    this.getCustomerType();
    this.getTypeList();
    this.getAreaList();
    this.setTableHeight();
  },
  mounted() {
    let _this = this;
    window.onresize = () => {
      return (() => {
        _this.setTableHeight();
      })();
    };
  },
  methods: {
    handleSizeChange(val) {
      this.size=val
      let a={
        size:this.size,
        page:this.page,
        customerIds:this.form.customerId,
        customerAreaIds:this.form.customerAreaIds.length?this.form.customerAreaIds.join(','):'',
        customerTypeIds:this.form.customerTypeIds && this.form.customerTypeIds.length?this.form.customerTypeIds.join(','):'',
        SCustomerIds:this.form.sCustomerId,
        FCustomerIds:this.form.fCustomerId
      }
      this.relevance(a)
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page=val
        let a={
        size:this.size,
        page:this.page,
        customerIds:this.form.customerId,
        customerAreaIds:this.form.customerAreaIds.length?this.form.customerAreaIds.join(','):'',
        customerTypeIds:this.form.customerTypeIds && this.form.customerTypeIds.length?this.form.customerTypeIds.join(','):'',
        SCustomerIds:this.form.sCustomerId,
        FCustomerIds:this.form.fCustomerId
      }
        this.relevance(a)
        console.log(`当前页: ${val}`);
      },
    selectRow(row, column, event) {
      this.selection=this.$refs['table1'].toggleRowSelection(row)
      console.log(this.$refs['table1'].selection,'[[[[[[[]]]]]]]',this.selection)
    },
    relevance(a){
      console.log(a)
      crudBasGoods.relevance(a).then(res=>{
        this.tabledata=res.data.content
        this.total=res.data.totalElements
        console.log(res)
        this.dialogVisible = true
      })
    },
    tuery(){
      console.log('333333333333',this.form.sCustomerId,this.form.fCustomerId)
      let a={
        size:this.size,
        page:this.page,
        customerIds:this.form.customerId,
        customerAreaIds:this.form.customerAreaIds.length?this.form.customerAreaIds.join(','):'',
        customerTypeIds:this.form.customerTypeIds && this.form.customerTypeIds.length?this.form.customerTypeIds.join(','):'',
        SCustomerIds:this.form.sCustomerId,
        FCustomerIds:this.form.fCustomerId
      }
      console.log('222222222222',a)
    this.relevance(a)
    },
    resetQuery() {
      this.form.customerId='';
      this.form.customerAreaIds=[];
      this.form.customerTypeIds=[];
      this.form.sCustomerId='';
      this.form.fCustomerId='';
      this.size=20
      this.page=1
      this.relevance()
    },
    save(){
      let resultList=this.$refs['table1'].selection
      let goodsIdList=this.crud.selections.map(item=>{return item.id})
      crudBasGoods.bindCustomers({goodsIdList:goodsIdList,resultList:resultList}).then(res=>{
        if(res.status===200){
          this.$message({
                message: res.msg,
                type: 'success'
              });
        }
      })
    },
    yes(){
      this.$refs['table1'].selection.map(item=>{
        return item.isAllowSale=1
      })
    },
    no(){
      this.$refs['table1'].selection.map(item=>{
        return item.isAllowSale=0
      })
    },
    permit(row){
      row.isAllowSale=1
    },
    notallow(row){
      row.isAllowSale=0
    },
    // getBrandList() {
    //   getBrandList({page: 0, size: 999}).then(res => {
    //     this.brandList = res.data.content
    //   })
    // },
    getCustomerType() {
      getCustomerTypeTree({page: 0, size: 999}).then(res => {
        this.CustomerType = res
      })
    },
    getTypeList() {
      getTypeList({ page: 0, size: 999 }).then((res) => {
        this.typeList = res;
      });
    },
    getAreaList() {
      getAreaTree().then((res) => {
        this.areaList = res;
      });
    },
    setTableHeight() {
      const ratio = this.crud.getRatio() / 100;
      this.tableHeight = (window.screen.height - 300 * ratio) / ratio;
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },
    getNoStr(val, type, prop) {
      let str = "";
      val.forEach((item) => {
        const itemNode = this.getTreeName(this[type], item);
        str = this.getNode(itemNode, str);
      });
      this.query[prop] = str;
    },
    getTreeName(treeList, id) {
      let _this = this;
      for (let i = 0; i < treeList.length; i++) {
        let treeItem = treeList[i];
        if (treeItem.id === id) {
          return treeItem;
        } else {
          if (treeItem.children && treeItem.children.length > 0) {
            let res = _this.getTreeName(treeItem.children, id);
            if (res) {
              return res;
            }
          }
        }
      }
    },
    getNode(node, str) {
      if (node.children) {
        for (let i = 0; i < node.children.length; i++) {
          str = this.getNode(node.children[i], str);
        }
      }
      return (str += node.id + ",");
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.afterRefresh]() {
      this.crud.data.forEach((item) => {
        if (item.imageUrl && item.imageUrl !== "null")
          this.$set(item, "image", JSON.parse(item.imageUrl)[0].path);
      });
      return true;
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {},
    toDetail(row) {
      this.$router.push({
        path: "basGoodsDetail/" + row.id,
        query: { id: row.id },
        meta: { title: "商品档案详情" },
      });
    },
    toAdd() {
      this.$router.push({
        path: "basGoodsDetail/0",
        query: { id: 0 },
        title: "新增商品档案",
      });
    },
    toCopy(row) {
      let _data = JSON.parse(JSON.stringify(row));
      _data.code = row.code + "1";
      localStorage.setItem("goodsForm_" + _data.code, JSON.stringify(_data));
      //打开一个新增界面
      this.$router.push({
        path: "/bas/goods/basGoodsDetail/" + _data.code,
        query: { id: _data.code },
        title: "新增商品档案",
      });
    },
    pushBasGoodsToMd(){
      crudBasGoods.pushBasGoodsToMd({ids:this.crud.selections.map(item=>item.id).join(',')}).then(res=>{
        if (res.status === 200){
          this.$message.success('操作成功')
          this.crud.refresh()
        }else {
          this.$message.error(res.msg)
        }
      }).catch(err=>{
        that.crud.loadingClose()
      })
    },
  },
};
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
